/**
 * 表单参照选择----选择单据
 */
mini.parse();
var grid = mini.get("datagrid1");
var cancel;

function SetData(data) {
    var data = mini.clone(data);
    var value = data.value;
    cancel = data.cancel;

    $.ajax({
        url: ajaxUrl + "/formList/list.do",
        type: "post",
        dataType: "json",
        success: function(grid_data) {
            console.log(grid_data);
            grid.loading();
            grid.setData(grid_data.data);
            // 默认选中
            grid.findRows(function (row) {
                if (row.formListId == value) {
                    grid.select(row);
                }
            });

        },
        error : function(data){
            // alert('获取失败');
        }
    });

   
}

//确定按钮之前
function onTableOk() {
    var grid = mini.get("datagrid1");
    var row = grid.getSelecteds()[0];

    if(row == undefined) {
        mini.alert('请选择单据！');
    }else {
        return row; //返回选中的数据给父组件
    }
}

//字段唯一验证
function onSelectionChanged(e) {
    var row = e.selected;
    if(e.selected != undefined) {
        if(row.formListId == cancel) {
            grid.deselect(row);
            mini.alert("此表单已被选择！");
        }
    }
}

//确定按钮
function onOk(e) {
    CloseWindow("ok");
}
//取消按钮
function onCancel(e) {
    CloseWindow("cancel");
}

function CloseWindow(action) {

    if (window.CloseOwnerWindow)
        return window.CloseOwnerWindow(action);
    else
        window.close();
}
